home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1999 April / Cd Pc Users extra 19 abril 1999.iso / Prog / Inst / Js02 / js02.exe / jscripts / timerv03.js < prev   
Encoding:
JavaScript  |  1998-12-06  |  1.4 KB  |  41 lines

  1. //-----------------------------------------------------------
  2. // JavaScript Code for Navigator 4+ and Internet Explorer 4+
  3. //------------------------------------------------------------
  4. // TIMER CODE VERSION 3 WITH POSSIBILITY TO STOP TIMER
  5. // working for Navigator 4+ and Internet Explorer
  6. // s0=0 m0=0 h0=0 signe_s1=0 itime=0 dtime=500 (in ms) :: Initialization
  7. // EX: begin_timer(0,0,0,0,0,timer,500)
  8. // timer: time this timer in s (second)
  9. // dtime: timeout in millisecond 500 recommended
  10. // function end_timer() must be defined by client ex : function end_timer2(ly){}
  11. // k : index of function gernerated
  12. //-----------------------------------------------------------
  13. var timeout_id_begin_timer3=null;
  14.  
  15. function begin_timer3(k,ly,s0,m0,h0,signe_s1,itime,timer,dtime) {
  16.      if (itime < timer ) {   
  17.  
  18.     var d1 = new Date();
  19.     var s1 = d1.getSeconds();
  20.     var m1 = d1.getMinutes();
  21.     var h1 = d1.getHours();
  22.  
  23.     if (signe_s1==0){   
  24.         s0=s1;
  25.         m0=m1;
  26.         h0=h1;
  27.         signe_s1=1;
  28.         timeout_id_timer=null;
  29.     }                
  30.     itime=(h1-h0)*3600+(m1-m0)*60+s1-s0;
  31.     timeout_id_begin_timer3=setTimeout("begin_timer3("+k+",'"+ly+"',"+s0+","+m0+","+h0+","+signe_s1+","+itime+","+timer+","+dtime+")", dtime);               
  32.     }
  33.                                   
  34.     if (itime > timer-1) {   
  35.         clearTimeout(timeout_id_begin_timer3);
  36.         timeout_id_begin_timer3=null;
  37.           end_timer3(k);
  38.     }
  39.  
  40. }
  41.